<?php

namespace Admin\Controller;

class CommentController extends AdminController {

    public function index(){
        $orderlog = M("orderlog");
        $orderlog_comment = M("orderlog_comment");

        $map = array();
        //$map['orderlog.is_comment'] = 1;

        $data = $orderlog_comment
            ->where($map)->order('comment_id desc')
            ->field('*')
            ->select();

        foreach($data as $k=>$v){
            $logmap['user_id'] = $v['student_id'];
            $logmap['comment_id'] = $v['comment_id'];
            $logdata = $orderlog->where($logmap)->order('orderlog.id desc')->find();
            $data[$k]['order_sn'] = $logdata['order_sn'];
            $data[$k]['eventtime'] = $logdata['eventtime'];
            $data[$k]['content'] = $logdata['remark'];

            $rs = M("user_teacher")->where(array('user_id'=>$v['teacher_id']))->find();
            $data[$k]['teacher_name'] = $rs['relname'];
            $rs = M("user_parent")->where(array('user_id'=>$v['student_id']))->find();
            $data[$k]['student_name'] = $rs['name'];
        }

        $this->assign('tab',$_GET['tab']);
        $this->assign('lists',$data);
        $this->display("index");

    }

    public function shenheComment(){
        $orderlogComment = M("orderlog_comment");

        $map['log_id'] = I('post.log_id');
        $data['is_shenhe'] = I('post.is_shenhe');

        $rs = $orderlogComment->where($map)->save($data);
        if($rs){
            $data['error'] = 0;
            $data['msg'] = '修改成功';
        }else{
            $data['error'] = 1;
            $data['msg'] = '修改失败';
        }
        echo json_encode($data);
    }

}
